<?php
/**
 * User: Jerry
 * Date: 2017/5/24
 * Time: 11:17
 */

namespace SDXApi\Model;


use Think\Model;

/**
 * Class CommunityTemplateContentModel
 * @author Jerry
 * @package SDXApi\Model
 */
class CommunityTemplateContentModel extends Model
{
    /**
     * @var string
     */
    protected $tableName = 'community_content';

    /**
     * @author Jerry
     * @param int $id
     * @return mixed
     */
    public function findContentByTemplateId($id = 0)
    {
        $where = array(
            'template_id'   =>  $id,
        );

        $field = 'content, sort';

        return $this->field($field)->where($where)->find();
    }

    /**
     * @author Jerry
     * @param $data
     * @return mixed|string
     */
    public function insertContent($data)
    {
        try{
            if ($this->create($data)) {
                return $this->add();
            }

            return $this->getDbError();
        }catch (\ErrorException $errorException) {
            E('文章内容插入错误');
        }
    }
}